clearvars -except Globaloption option

%% Saving parameter estimates to automatically update the paper
fID = fopen(['../../results/tables_main/US/pre1946/Table_pre_us_break.tex'], 'w');

%% ONE VAR with break Results

load 'MAT/res_annual_VAR_nodebt_US_before1946_demean.mat';

[mean(log(taxrevgdp(date <= 1860))), mean(log(taxrevgdp(date > 1860)))]
[mean(log(spendgdp(date <= 1860))), mean(log(spendgdp(date > 1860)))]

%
deltalogg = [log(spendgdp(1)) - log(spendgdp0); log(spendgdp(2:end)) - log(spendgdp(1:end - 1))];
deltalogtau = [log(taxrevgdp(1)) - log(taxrevgdp0); log(taxrevgdp(2:end)) - log(taxrevgdp(1:end - 1))];

fprintf(fID, '\\newcommand{\\preusVarMeanhCivil}{%4.2f}\n', 100 * mean(deltalogtau));
fprintf(fID, '\\newcommand{\\preusVarMeaniCivil}{%4.2f}\n', mean(log(taxrevgdp)));
fprintf(fID, '\\newcommand{\\preusVarMeanjCivil}{%4.2f}\n', 100 * mean(deltalogg));
fprintf(fID, '\\newcommand{\\preusVarMeankCivil}{%4.2f}\n', mean(log(spendgdp)));

load 'MAT/benchmark_US_before1946_demean.mat';
fprintf(fID, '\\newcommand{\\preuskzeroxCivil}{%4.2f}\n', k0x);
fprintf(fID, '\\newcommand{\\preuskonexCivil}{%4.2f}\n', k1x);
fprintf(fID, '\\newcommand{\\preusmeanpvsurplusCivil}{%4.2f}\n', mean(s));
fprintf(fID, '\\newcommand{\\preusmeansurpluszerozCivil}{%4.2f}\n', mean(upper));
fprintf(fID, '\\newcommand{\\preusmeanpvsurpluspctCivil}{%4.2f}\n', 100 * mean(s));
fprintf(fID, '\\newcommand{\\preusmeansurpluszerozpctCivil}{%4.2f}\n', 100 * mean(upper));
fprintf(fID, '\\newcommand{\\preuspdgdpCivil}{%4.2f}\n', mean(exp(pxbar)));
fprintf(fID, '\\newcommand{\\preusgdpreturnCivil}{%4.2f}\n', 100 * mean(gdpreturn));
fprintf(fID, '\\newcommand{\\preusdebtgdpCivil}{%4.2f}\n', nanmean(gdebt));
fprintf(fID, '\\newcommand{\\preusdebtgdppctCivil}{%4.2f}\n', 100 * nanmean(gdebt));

fprintf(fID, '\\newcommand{\\preuspvstodebtCivil}{%4.2f}\n', 100 * nanmean(s) / nanmean(gdebt));

fprintf(fID, '\\newcommand{\\preussurpluspctCivil}{%4.2f}\n', 100 * (mean(taxrevgdp) - mean(spendgdp)));
A = corrcoef([gdebt(2:end) s'], 'rows', 'pairwise');

fprintf(fID, '\\newcommand{\\preuscorrpvsdebtCivil}{%4.2f}\n', A(2));
fprintf(fID, '\\newcommand{\\preusuppertodebtCivil}{%4.2f}\n', 100 * upper / nanmean(gdebt));

%% Close File
fclose(fID);
